<!-- post.html -->
{%  extends 'base.html'  %}
{% load markdown_deux_tags %}
{%  block title  %} {{ post.title }} {%  endblock  %}
{%  block headmessage  %}{{ post.title }}{% endblock %}
{%  block content  %}
<script src="/static/js/jquery-2.1.4.min.js"></script>
<script>
    $(document).ready(function () {
         $("#zan").click(function(){
           $.ajax({url:"/updatevote/",
                  data: {'postslug':$(this).next().val()},
                  success:function(res){
                    $(this).next().next().text("❤点赞"+"("+res+")");
                  }.bind(this)
          });
      });
        $("#dianzan").click(function () {
                 $("#zan").click();
        });
    });
    function go_delete(id,pid) {
        swal({
          title: "是否销毁该条评论？",
          text: "评论销毁后不可恢复，仅能联系管理员进行数据恢复。",
          icon: "warning",
          buttons: ["噢，不！", "是的!"],
          dangerMode: true,
        }).then((willDelete) => {
          if (willDelete) {
            swal("恭喜您！您已成功销毁该条评论", {
              icon: "success",
              buttons: "太棒了！",
            });
              var usr = '/' + id + '/' + pid;
              window.location = usr;
          } else {
            swal("已为您成功保该条评论！", {
                buttons: "谢谢！",
            });
          }
        });
    };
    function go_like(pid) {
        swal("您已成功添加到我的收藏", {
          icon: "success",
          buttons: "好哒！",
        });
        var usr = '/add_collect/' + pid;
        window.location = usr;
    };
    function go_over(pid) {
        swal({
          title: "是否取消收藏该条新闻？",
          text: "新闻收藏取消后可重新收藏该新闻。",
          icon: "warning",
          buttons: ["点错了！", "是的!"],
          dangerMode: true,
        }).then((willDelete) => {
          if (willDelete) {
            swal("已取消收藏该条新闻", {
              icon: "success",
              buttons: "好哒！",
            });
              var usr = '/collect/del/' + pid;
              window.location = usr;
          };
        });
    };
</script>
    <div  id="BK" style="height: 662px;position: absolute;z-index: -1"></div>
    <div class="user-profile-post" id="BK" style="width: 70%;margin-left: 10%;margin-top: 20px">
        <div class="row">
            <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
                <div class="user-profile-post-name">
                    <h2><a href="/post/{{ post.id }}">{{ post.title }}</a></h2>
                    <p style="color: orangered">发布时间: {{ post.pub_date | date:'Y年m月d日, H:i'}}</p>
                    <i style="color: deeppink;text-decoration: underline">关键人物：{{ post.people }}</i>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                <div class="profile-user-post-content">
                <div>
                    <p>{{ post.body|markdown }}<p>
                    <p style="color: deeppink">文章来源：{{ post.source }}</p>
			    </div>
                    <div class="user-post-reply">
                        <div class="btn-group">
                        <a id="zan" type="hidden">
                        </a>
                            <input type="hidden" value="{{ post.id }}">
                            <button class="btn btn-white btn-xs" id="dianzan"><i class="fa fa-thumbs-up"></i> 点赞 ({{ post.likes }})</button>
                            <button class="btn btn-white btn-xs" onclick="javascrtpt:window.location.href='#comment'"><i class="fa fa-comments"></i> 评论</button>
                            {% if post.id in collect %}
                            <button class="btn btn-white profile-time-ds-none btn-xs" onclick="go_over({{ post.id }})"><i class="fa fa-star"></i> 已收藏</button>
                            {% else %}
                            <button class="btn btn-white profile-time-ds-none btn-xs" onclick="go_like({{ post.id }})"><i class="fa fa-share"></i> 收藏</button>
                            {% endif %}
                        </div>
                    <div style="float: right">
                        <span>
                            <button class="btn btn-white profile-time-ds-none btn-xs" onclick="javascrtpt:window.location.href='/post/{{ post.id|add:1 }}'">↑ 上一章</button>&nbsp;&nbsp;
                            <button class="btn btn-white profile-time-ds-none btn-xs" onclick="javascrtpt:window.location.href='/post/{{ post.id|add:-1 }}'">↓ 下一章</button>&nbsp;&nbsp;
                            <button class="btn btn-white profile-time-ds-none btn-xs" onclick="javascrtpt:window.location.href='javascript:history.back(-1)'"><i class="fa big-icon fa-home"></i> 返 回</button>&nbsp;&nbsp;
                        </span>
                    </div>
                    </div>
                </div>
            </div>
        </div>
        <br>
    <!-- 评论 -->
        <div class="row">
            <div class="col-md-12">
                <div class="panel panel-primary" style="border-color: pink">
                    <div class="panel-heading" style="background-color: pink;border-color: pink"><h3>评论区</h3></div>
                    {% for com in comment %}
                    <div class="panel-body">
                            <b>{{ com.nickname }}</b><br>
                            {{ com.message }}
                    </div>
                        <div class="panel-footer" style="border-bottom: 1px solid pink;border-top: none"><em>{{ com.pub_time }}</em>
                        {% if com.nickname == username %}
                        <span class="glyphicon glyphicon-trash" style="float: right;margin-top: 4px" onclick="go_delete({{ com.id }},{{ post.id }})"></span>
                        {% endif %}
                        </div>
                    {% endfor %}
                </div>
            </div>
        </div>
    <!-- 评论 -->
    <!-- 发表评论 -->
        <div class="login-bg" id="comment">
            <form name="my form" action="/post/{{ post.id }}" method="POST">
                {% csrf_token %}
                <div class="login-textarea-area">
                    <div class="note"><b>在这里写下你想说的话吧~</b></div>
                    <textarea name="comment" class="contact-message" cols="30" rows="10" required="required"></textarea>
                    <i class="fa fa-comment login-user" style="margin-top: -15px;border: none"></i>
                </div>
                <button class="btn btn-white btn-xs" type="submit"><i class="fa fa-comments"></i> 评论</button>
                <button class="btn btn-white btn-xs" type="reset"><i class="fa big-icon fa-edit"></i> 清空评论</button>
            </form>
        </div>
    <!-- 发表评论 -->
    </div>
    <br>
{%  endblock  %}

